//
//  ZDWalletHeaderView.m
//  特种车调度
//
//  Created by 陈宇 on 15/8/30.
//
//

#import "ZDWalletHeaderView.h"
#import "ZDWalletLog.h"

@interface ZDWalletHeaderView ()

@property (nonatomic, weak) UILabel *nameLabel;
@property (nonatomic, weak) UILabel *priceLabel;
@property (nonatomic, weak) UIImageView *arrowView;

@end

@implementation ZDWalletHeaderView

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
        
        self.contentView.backgroundColor = [UIColor whiteColor];
        
        UILabel *label = [[UILabel alloc] init];
        label.textColor = [UIColor darkGrayColor];
        label.font = [UIFont systemFontOfSize:13.f];
        [self.contentView addSubview:label];
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(self.contentView);
            make.left.mas_equalTo(self.contentView).offset(15.f);
        }];
        self.nameLabel = label;
        
        UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"arrow_down"]];
        [self.contentView addSubview:imageView];
        [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(self.contentView);
            make.right.mas_equalTo(self.contentView).offset(-15);
        }];
        self.arrowView = imageView;
        
        UILabel *priceLabel = [[UILabel alloc] init];
        priceLabel.textColor = BMColor(249, 128, 114, 1);
        priceLabel.font = [UIFont systemFontOfSize:13.f];
        [self.contentView addSubview:priceLabel];
        [priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(self.contentView);
            make.right.mas_equalTo(imageView.mas_left).offset(-10.f);
        }];
        self.priceLabel = priceLabel;
        
        UIView *seperatorView1 = [UIView new];
        seperatorView1.backgroundColor = [UIColor groupTableViewBackgroundColor];
        [self.contentView addSubview:seperatorView1];
        [seperatorView1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.right.mas_equalTo(self.contentView);
            make.height.mas_equalTo(1);
        }];
        
    }
    return self;
}

- (void)setMonth:(ZDWalletMonth *)month
{
    _month = month;
    self.nameLabel.text = _month.name;
    
    if (kRoleType == 0) {
        double total = 0;
        for (ZDWalletLog *log in _month.incomeDetails) {
            total += log.countMoney;
        }
        self.priceLabel.text = [NSString stringWithFormat:@"本月收入:%.2f", total];
    }
    
    if (_month.selected) {
        self.arrowView.transform = CGAffineTransformMakeRotation(M_PI);
    } else {
        self.arrowView.transform = CGAffineTransformIdentity;
    }
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    _month.selected = !_month.selected;
    
    if (_clickAction) {
        _clickAction();
    }
}

@end
